-
-
Notifications
You must be signed in to change notification settings - Fork 498
Implement lua-vec - vectors as native Lua datatype #1728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
So, whats people's opinion on this? |
|
I like the changes.
We can have a submodule for Lua. In this way, it will be easy to track the changes. |
|
So, we should create a separate repo? |
Hmm, that doesn't seem like a good idea. Let's just create a new branch for Lua. I'd do it like this:
|
|
My approach would be:
This approach is compatible with the submodule system proposed in #319. |
|
AFAIK There is no official Lua repo on GitHub, if that's what you meant by Fork Lua repo. |
|
Okay I think I did it. |
There's an official mirror on GitHub of the Lua repo, here. It has a tag for every released Lua version, all the way back to 5.1. I agree that keeping the history may come in handy in the future for some cherry-picks, for updating Lua more easily, or whatever, but I would also understand not keeping the original commit history if it's deemed too verbose. |
|
Please look at MTA org's /lua repo. |
|
i noticed you call the vector type in Lua only "vec" which is inconsistent to the other types: "number", "table", ... |
|
since Lua uses doubles, shouldn't the vectors not use doubles too? |
|
There would be no benefit of the additional memory required. MTA uses float vectors everywhere, the additiona precision would be lost. |
|
maybe cVector |
|
btw. since my knowledge is not too big about instruction sets |
I'm not sure if you were talking to me, but yeah, it looks good to me. I was just pointing out that the original approach that @qaisjp suggested was possible due to the existence of that mirror. |
|
Anyways, the submodule stuff #2112 |
|
The main bottleneck is probably still the Lua side, rather than the actual maths. Not worth the headache. But where I think we might benefit from SSE is our vector stuff.. although I wonder why MSVC doesn't use SSE by default there.. Should be pretty trivial I belive. |
…into feature/native-vectors
|
Edit: Turns out there's 2 lua-vec branches: One which is a first-class value like a number, bool, etc.. and the second one (this) treats it as GCObject's. Obviously the first one is faster, but comes at the expense of making |
|
@Pirulax A great amount of time has passed, but do you still want to get this pull request merged? |
|
This is very useful and would be a good update. |
|
Bump? |
|
Any news on this? Would make my current project way easier and faster instead of countless float math operations each time. |
|
I think it can be merged, no? Edit: Actually nvm, this is just the veclib, i'd still have to change all the parser stuff and whatnot to return this type instead of Vector3... |
This PR aims to fix the issue we have with userdata vectors. (#321)
As discussed on discord (and maybe even in the issue itself), using Lua tables would be only marginally better, and the performance benefit would probably be lost when doing table <=> conversion.
Note: I've tested this with bytecode as well (Compiled all default resources, and they all worked perfectly). So no backwards compatibility issues here.
This code(Lua-vec) was "stolen" from here.
I need opinions: Although I've already discussed this with @Woovie, I'd be great if others could give their feedback.
I think naming the datatype as
vectorwould be totally okay (the function table will be namedvectorin lower case, just so we keep Lua's naming convention. We can just alias it toVectorin a form of a global variable)Features in
lua-vec:.x, or even.xxyz,.xx(like in hlsl)Lua-vecuses no additional memory at all! Its free! [2][1]: A Vector4 needs 4 bytes for
lua_newuserdata, anothersizeof(unsigned long)+sizeof(void*)+sizeof(CLuaVector4D(which is 16 + 4 bytes) inCIdArray[2]: Its value is stored in a
GcObjectunion. This is where the userdata is stored as well, so, compared to the userdata implementation, we use no additional memoryTodo:
veccallable (add __call metamethod), right now vectors can only be created withvec.newArgumentParserandCScriptArgReaderto read the new type as aVector2/3/4DVector2/3/4fromnative vectornative vectorfrom existingVector2/3/4(only way to implement this cleanly is to use.x.y.z)LUA_TVECinCLuaArgument(WriteToBitStreamandReadFromBitStream)Tests:
Resource used: vectest.zip
Scene rendering with
smallpt.lua(from Lua-vec):Command:
runsmallpttests 250 250 4 falseCommand: `runsmallpttests 250 250 4 true`
Syntethic add/create/mul/sub benchmark: